<template>
  <!-- <t-dialog :header="header" :visible.sync="visible" :onClose="closeDialog" :closeOnOverlayClick="false"
    :confirmBtn="null" width="90%" top="5%">
    <div style="height: 60vh"> -->
  <t-tabs size="medium" v-model="tabValue">
    <t-tab-panel value="1" label="基本信息" :destroyOnHide="true" :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']">
      <t-form labelWidth="160px">
        <t-row style="align-items: stretch" :gutter="14">
          <t-col :span="12">
            <t-card class="step-card" size="small" title="基本信息">
              <t-form-item label="序号：" name="sort">
                {{ dataList.sort }}
              </t-form-item>
              <t-form-item label="指标名称：" name="systemId">
                <!-- <t-tree-select disabled filterable style="width: 390px"
                  :treeProps="{ keys: { value: 'id' }, valueMode: 'onlyLeaf' }" v-model="dataList.systemId"
                  :data="profTitOptions" placeholder="指标名称"></t-tree-select> -->
                {{ dataList.systemId | filterByTree(profTitOptions) }}
              </t-form-item>
              <t-form-item label="分值：" name="score">
                {{ dataList.score }}
              </t-form-item>
              <t-form-item label="排名：" name="ranking" v-if="isShowRanking">
                {{ dataList.ranking | filterByDict(dict.type.kjpt_score_ranking) }}
              </t-form-item>
              <t-form-item label="金额（万元）：" name="money" v-if="isShowMoney">
                {{ dataList.money }}
              </t-form-item>
              <t-form-item label="成果名称：" name="name">
                {{ dataList.name }}
              </t-form-item>

              <t-form-item label="备注：" name="note">
                {{ dataList.note }}
              </t-form-item>
              <t-form-item label="取得年度：" name="year">
                {{ dataList.year }}
              </t-form-item>
            </t-card>
          </t-col>
        </t-row>



      </t-form>
    </t-tab-panel>
    <t-tab-panel value="2" label="附件" :destroyOnHide="true" :class="[reviewOpen ? 'tab-full-panel' : 'tab-panel']">
      <t-form colon labelWidth="160px">
        <t-form-item label="" name="">
          <t-table row-key="id" :columns="projectFileColumns" :data="projectFileData">
            <template #id="{ row, rowIndex }">
              {{ rowIndex + 1 }}
            </template>
            <template #c1="{ row }">
              <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1
                }}</a>
              <div v-else>{{ row.c1 }}</div>
            </template>
            <template #op="{ row }">
              <div v-for="(item, index) in row.fileLists" :key="index">
                <a class="t-button-link" target="_blank" :href="item.url">
                  {{ item.name }}
                </a>
              </div>
            </template>
          </t-table>
        </t-form-item>
      </t-form>
    </t-tab-panel>
  </t-tabs>
  <!-- </div>

  </t-dialog> -->
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import { getFiles } from "@/api/common";

export default {
  dicts: ["kjpt_score_ranking"],
  components: {
  },
  props: {
    objId: [String, Number],
    header: String,
    isDialog: {
      type: Boolean,
      default: true
    },
    reviewOpen: {
      type: Boolean,
      default: false
    },
    hideInfo: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      isShowRanking: false,
      isShowMoney: false,
      file_domain: VITE_FILE_DOMAIN,
      projectFileData: [
        {
          id: 1,
          c1: "相关附件",
          c2: "否",
          moduleKey: "kjptzbfj",
          require: true,
          fileIds: [],
          fileLists: [],
          accept: "application/pdf,image/*"
        }
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "left",
        },
      ],
      site_tag: import.meta.env.VITE_SITE_TAG,
      visible: true,
      tabValue: "1",
      dataList: {},
      profTitOptions: [],
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler (val) {
        if (val) {
          this.getObj(val)



        }
      }
    },
  },
  methods: {
    async getObj (val) {


      this.$api.kjpt.project.scoreDetail(val).then(response => {
        if (response.data) {
          this.dataList = response.data
          this.getProfTitTreeSelect()
        }
      }).catch((e) => {

      });


      getFiles(this.objId).then((res) => {
        const files = {}
        res.data.forEach((item) => {
          if (!files[item.moduleKey]) {
            files[item.moduleKey] = []
          }
          files[item.moduleKey].push({
            name: item.fileName,
            url: item.fullFilePath,
            id: item.id,
            filePath: item.filePath
          })
        })
        this.projectFileData.forEach((val, index) => {
          this.projectFileData[index].fileLists = files[val.moduleKey] || [];
          this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
        })

      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });

    },
    getProfTitTreeSelect () {
      this.$api.kjpt.project.systemTree().then(response => {
        this.profTitOptions = response.data;
        this.onProfTitIdChange()
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    onProfTitIdChange () {

      if (!this.dataList || !this.dataList.systemId) {
        return
      }
      this.$api.kjpt.project.systemDetail(this.dataList.systemId).then(response => {
        if (response.data) {
          this.dataList.score = response.data.score
          this.dataList.note = response.data.note
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });

      var systemId = this.dataList.systemId + ''
      if (systemId.length > 5) {
        systemId = systemId.substring(0, 5)
      }

      this.isShowRanking = false
      if (systemId.includes('10101') || systemId.includes('10102') || systemId.includes('10104')) {
        this.isShowRanking = true
      }

      this.isShowMoney = false
      if (systemId.includes('10201')) {
        this.isShowMoney = true
      }
    },
    closeDialog () {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel {
  padding: 10px;
  height: 100%;
}

.t-form__item {
  margin-bottom: 6px
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}

.content_style {
  font-size: 12pt;
  font-family: 宋体;
  line-height: 1.5;
}


.t-tab-panel {
  padding: 10px;
}

.tab-panel {
  height: calc(65vh - 64px);
  overflow: scroll;
}

.tab-full-panel {
  height: calc(80vh - 64px);
  overflow: scroll;
}
</style>
